#!/bin/sh

if [ ! -f modules/ivi44.ko ] ; then
	echo "Error: please make modules first."
	exit 1
fi

start() {
	if ( lsmod | grep "ivi44" ) ; then
		echo "Error: modules exist, run 'control restart' instead."
		exit 1
	fi
	echo "Starting IVI44 modules: "
	insmod modules/ivi44.ko
	echo "insmod ivi44.ko"
	if [ ! -e /dev/ivi ] ; then
		mknod /dev/ivi44 c 324 0
		echo "mknod /dev/ivi44 c 324 0"
	fi
	return 0
}

stop() {
	if ( lsmod | grep "ivi44" ) ; then
		echo "Stopping IVI44 modules: "
		rmmod ivi44
		echo "rmmod ivi44"
		rm /dev/ivi44
		echo "rm /dev/ivi44"
	else
		echo "Error: modules do not exist."
	fi
	return 0
}

case "$1" in 
	start)
		start
		;;
	stop)
		stop
		;;
	restart|reload)
		stop
		start
		;;
	*)
		echo "Usage: control {start|stop|restart|reload}"
		exit 1
esac

exit 0
